$(function() {
    $.ajaxSetup({cache: false});
    $("#payPassWd").blur(function(){
       checkPayPassWd();
    });
    $("#rePayPassWd").blur(function(){
        checkRePayPassWd();
    });

    $("#pwdAnswer").blur(function(){
        checkPwdAnswer();
    });
});


function testNewPassword(val){
    var num = /^(?:\d*)$/;
    var upperLetter = /^([A-Z]*)$/;
    var lowLetter = /^([a-z]*)$/;
    var special = /^([\~\!\@\#\^\*\-\[\]\{\}\:\?]*)$/;
    var isNewPassword = /^[a-zA-Z0-9\~\!\@\#\^\*\-\[\]\{\}\:\?]{8,20}$/;
    var isNotNewPassword = /^(?:\d*|[a-zA-Z]*|[\w\~\!\@\#\^\*\-\[\]\{\}\:\?]*)$/;

    var tip1 = "至少使用8-20位大小写英文字母、数字或标点符号两种组成";
    var tip2 = "输入字符有误，支持的字符为~!@#^*_-[],{}:?";
    if(val.match(isNotNewPassword) == null){
        return tip2;
    }
    if(val.match(num)!=null || val.match(upperLetter)!=null || val.match(lowLetter)!=null || val.match(special)!=null ){
        return tip1;
    }
    if(val.match(isNewPassword) == null){
        return tip1;
    }
}

function isRemarkChar(val){
    var remark = /^[\u4E00-\u9FA5a-zA-Z0-9\~\!\@\#\^\*\-\[\]\{\}\:\?]+$/;
    var tip = "请使用中文、英文字母、数字和标点符号的组合，支持的标点字符为~!@#^*_-[],{}:?";
    if(val.match(remark) == null){
        return tip;
    }
}


function checkPayPassWd(){
    $("#payPassWdTip").hide();
    var tip = testNewPassword($("#payPassWd").val());
    if(tip){
        $("#payPassWdTip").html(tip).show();
        return false;
    }
    return true;
}

function checkRePayPassWd(){
    $("#rePayPassWdTip").hide();
    var tip = testNewPassword($("#rePayPassWd").val());
    if(tip){
        $("#rePayPassWdTip").html(tip).show();
        return false;
    }
    if($("#payPassWd").val() != $("#rePayPassWd").val()){
        $("#rePayPassWdTip").html("两次输入支付密码不相同").show();
        return false;
    }
    return true;
}

function checkCustProession(){
    $("#custProessionTip").hide();
    if($("#custProession").val() == ""){
        $("#custProessionTip").show();
        return false;
    }
    return true;
}

function checkPwdQuestion(){
    $("#pwdQuestionTip").hide();
    if($("#pwdQuestion").val() == ""){
        $("#pwdQuestionTip").show();
        return false;
    }
    return true;
}

function checkPwdAnswer(){
    $("#pwdAnswerTip").hide();
    var tip = isRemarkChar($("#pwdAnswer").val());
    if(tip){
        $("#pwdAnswerTip").html(tip).show();
        return false;
    }
    return true;
}


function completeSubmit(){
    if(checkCustProession() && checkPayPassWd() && checkRePayPassWd() && checkCustProession() && checkPwdQuestion() && checkPwdAnswer()){
        $("#completeUserInfoForm").submit();
    }
}
